#coding=utf-8
import xlrd
import pandas as pd
import urllib2
import requests
from pymongo import MongoClient
from datetime import datetime
import sys

from com.local.hmh import Utils

reload(sys)
sys.setdefaultencoding("utf-8")

v = 0;
if  v or None or "":
    print("=====")

arr = ['a', 'b', 'c', ['a', 'b']];
arr2 = ['d', 'e'];
print(arr + arr2)
print(arr[2])
print(arr.__getitem__(1))
print(float("0"))
print(float("2017"))
print(float("222180.68"))
#print(float("元"))
print("11.11".isalnum())

'''
def mugle_data(content):
    result = [];
    lines = content.split('\n');
    for i in range(1, len(lines[0].split("\t")) -1):
        result.append({})
    for line in lines:
        eles = line.split("\t")
        for i in range(1, len(eles) - 1):
            print(eles[0] +":" + eles[i])
            result[i -1 ][eles[0]] = eles[i]
    return result;


url = "http://money.finance.sina.com.cn/corp/go.php/vDOWN_BalanceSheet/displaytype/4/stockid/603517/ctrl/all.phtml"
response = requests.request("get", "http://money.finance.sina.com.cn/corp/go.php/vDOWN_BalanceSheet/displaytype/4/stockid/603517/ctrl/all.phtml");
content = response.content.decode("GBK")
print(content)
res = mugle_data(content)
print res
'''
#lines = response.content.split("\n");
#for line in lines:
    #print line.decode("GBK")


#spaceline = 'hello he minhang'
#eles = lines[11].split("\t")
#for i in range(len(eles)):
 #   print eles[i]

'''
mgClient = MongoClient('localhost', 27017)
db = mgClient['test']
print(db.stock.find({"name": 'heminhang'})[0])
for ele in res:
    item = {"name": 'heminhang', 'sexy': 'boy', 'high':174, 'birthday': datetime.now() }
    db.stock.insert_one(item)
print(db.stock.count())
temp = db.stock.find_one({'长期股权投资': '155415449.30'})
print(temp)
exit()

fopen = open("data3.xls", 'w')

file="data.xls"
f = open(file, 'rb')
lines = f.readlines()
for line in lines:
    line = line.decode('gbk').encode('utf8')
    fopen.write(line)
    print line
fopen.close();
'''

file_url = 'http://basic.10jqka.com.cn/api/stock/export.php?type=report&code=000423&export=benefit'
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}
response = requests.request("get", file_url,  headers=headers)
content = response.content
path = Utils.save_finance_data('000423', 'tmp', content)
xls_file = pd.read_excel(path, headers=headers, index_col=0, skiprows=[0], encoding='utf-8')
Utils.remove_file(path)
series =  xls_file.loc['扣非净利润(元)']
value = series.get('2017-06-30')
print value

